package com.sikao.app.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.File;

/**
 * Created by Administrator on 2016/9/19.
 */
public class BitmapUtils {
	public static String bitmapFileZoom(String path) {
		File outputFile = new File(path);
		Boolean a = outputFile.exists();
		long fileSize = outputFile.length();
		final long fileMaxSize = 100 * 1024;
		if (fileSize >= fileMaxSize) {
			BitmapFactory.Options options = new BitmapFactory.Options();
			options.inJustDecodeBounds = true;
			BitmapFactory.decodeFile(path, options);
			int height = options.outHeight;
			int width = options.outWidth;

			double scale = Math.sqrt((float) fileSize / fileMaxSize);
			if (scale <= 1) {
				return path;
			}
			options.outHeight = (int) (height / scale);
			options.outWidth = (int) (width / scale);
			options.inSampleSize = (int) (scale + 0.5);
			options.inJustDecodeBounds = false;

			Bitmap bitmap = BitmapFactory.decodeFile(path, options);
			path = FileUtils.getInstance().imagePath + "output_image" + System.currentTimeMillis() + ".png";

			FileUtils.getInstance().saveFileToPath(bitmap, path);
			if (!bitmap.isRecycled()) {
				bitmap.recycle();
			}

		}
		return path;

	}
}
